<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'dictionary.jsp' starting page</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.3.4/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/wu.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icon.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
	$(function(){
		$("#dictionarys").submit(function(){
			var names=$("input[name='names']").val();
			var ranks=$("input[name='ranks']").val();
			if(names==""||names==null ){
				alert('字典不能为空');
				return false;
				}else if(names.length>20){
				alert('不能超出最大范围');
				return false;
				}
			if(ranks==""||ranks==null){
				alert('请为字典排序');
				return false;
			}else if(ranks.length>50){
				alert('不能超出最大范围');
				return false;
				}
			if(startshow==""||startshow==null){
				alert('请填入开始时间');
				return false;
			}
				return true;	
	});
	});
$(function(){
		$("#cff").submit(function(){
			var namechild=$("input[name='namechild']").val();
			var rankchild=$("input[name='rankchild']").val();
			if(namechild==""||namechild==null ){
				alert('字典不能为空');
				return false;
				}else if(namechild.length>20){
				alert('不能超出最大范围');
				return false;
				}
			if(rankchild==""||rankchild==null){
				alert('请为字典排序');
				return false;
			}else if(rankchild.length>50){
				alert('不能超出最大范围');
				return false;
				}
			if(startshow==""||startshow==null){
				alert('请填入开始时间');
				return false;
			}
				return true;	
	});
	});
	
	
	
	$(function(){
		$("#dict").datagrid({   
		    url:'${pageContext.request.contextPath}/dictionary?op=dict',   
		    columns:[[   
		        {field:'id',title:'编号'},
		        {field:'rank',title:'排序',width:100},  
		        {field:'dictname',title:'名称',width:400},   
		        {field:'rank',title:'序号',width:100},
		    ]],
		    fitColumns : true,
			autoRowHeight : false,
			striped : true,
			loadMsg : '请等待...',
			pagination : true,
			nowrap : true,
			rownumbers : true,
			singleSelect:true,
			fit : true,
				toolbar : [{
			 	text:'修改',
				iconCls : 'icon-edit',
				handler : function() {
					var obj = $("#dict").datagrid("getSelected");
					$("#id").val(obj.id);
					$("#door").window({   
					    width:600,   
					    height:400,   
					    modal:true ,
					    title:'修改字典',
					    iconCls:'icon-edit'
					});
					$("#fat").form('load',{
						name:obj.dictname,
						rank:obj.rank,
					});
					$("#dictchild").datagrid({   
		    		url:'${pageContext.request.contextPath}/dictionary?op=dictchild&secid='+obj.id,   
		    		columns:[[ 
		    			{field:'id',title:'序号',width:220,checkbox:true},  
		        		{field:'dictname',title:'名称',width:360,},
		        		{field:'rank',title:'排序',width:220},  
		    		]],
					toolbar : [{
			 				text:'添加',
							iconCls : 'icon-add',
							handler : function() {
									$("#secid").val(obj.id);
									$("#doorchild").window({   
					    			width:400,   
					    			height:200,  
					    			modal:true ,
					   		 		title:'添加子字典',
					    			iconCls:'icon-add'
					});
					}
					}, '-', {
							text:'删除',
							iconCls : 'icon-remove',
							handler : function() {
					 				var obj = $("#dictchild").datagrid("getSelected");
									var str=confirm("确认删除客户信息?");
									if(str==true){
									location.href='${pageContext.request.contextPath}/dictionary?op=deletedict&id='+obj.id;
							}
					}
					}]
					});
				}
					}, '-', {
							text:'添加',
							iconCls : 'icon-add',
							handler : function() {
									$("#adddoor").window({   
					    			width:600,   
					    			height:300,   
					    			modal:true ,
					    			title:'添加字典',
					    			iconCls:'icon-add'
							});
					}
					}, '-', {
					text:'删除',
					iconCls : 'icon-remove',
					handler : function() {
					 	var obj = $("#dict").datagrid("getSelected");
						var str=confirm("确认删除客户信息?");
						if(str==true){
							location.href='${pageContext.request.contextPath}/dictionary?op=deletedict&id='+obj.id;
					}
				}
			}] 
	});
	});
	
	$(function(){
		$('#cff').form({   
		    url:'${pageContext.request.contextPath}/dictionary?op=addsdict',   
		    onSubmit: function(){     
		    },   
		    success: function(data){   
 						var data = eval('(' + data + ')');  
 						if (data.success){   
     					   $('#doorchild').window('close');
     					   $("#dictchild").datagrid('reload');  
     				 }
		    }   
		});   
	});
	$(function(){
	var msg=$('#msg').val();
	if(msg!=""){
		$.messager.show({
			title:'info',
			msg:msg
		});
	}
	$('#msg').val("");
});
</script>
  </head>
  
  <body class="easyui-layout">
  <div><input type="hidden" id="msg" value="${e}"></div>   
    <div data-options="region:'center'">
    	<table id="dict"></table>
    	<!-- 修改 -->
    	<div id="door" style="text-align:center;line-height:15px;padding-top:5px;">
    		<form action="dictionary.html?op=updatedict" id="fat" method="post">
    		<div >	
    			<input name="id" id="id" type="hidden">
    			<h3 style="text-align:left;">主字典</h3>
			    <label for="name">名称:</label> 
			    <input class="easyui-validatebox" type="text" name="name" style="height:25px;width:300px" ></input>
			    <label for="rank">&nbsp;&nbsp;排序:</label>  
			    <input class="easyui-validatebox" type="text" name="rank" style="height:25px;width:100px"></input>
			</div><br/>
			<hr/>
			
    		<div>
    			<h3 style="text-align:left;">子字典</h3>
			    <table id="dictchild"></table>
			</div>
			
			<div style="text-align:right; padding-right: 20px">
				<input type="submit" value="提交" />
			</div>
		</form>			
    	</div>
    	<!-- 添加 -->
    	<div id="adddoor" style="text-align:center;line-height:15px;padding-top:5px;">
    		<form action="${pageContext.request.contextPath}/dictionary?op=savedict" method="post" id="dictionarys">
    		<div >
    			<input name="ids" id="ids" type="hidden">
    			<h3 style="text-align:left;">主字典</h3>
			    <label for="names">名称:</label> 
			    <input class="easyui-validatebox" type="text" name="names" style="height:25px;width:300px" ></input>
			    <label for="ranks">&nbsp;&nbsp;排序:</label>  
			    <input class="easyui-validatebox" type="text" name="ranks" style="height:25px;width:100px"></input>
			</div><br/>
			
			<div style="text-align:right; padding-right: 20px">
				<input type="submit" value="提交" />
			</div>
		</form>			
    	
    	</div>
    </div>
    	<!-- 添加子字典 -->
		<div id="doorchild" style="text-align:center;line-height:15px;padding-top:5px;">
			<form id="cff" method="post">
    			<div >
    				<input name="secid" id="secid" type="hidden">	
			    	<label for="namechild">名称:</label> 
			    	<input class="easyui-validatebox" type="text" name="namechild" style="height:25px;width:200px"></input>
			    	<label for="rankchild">&nbsp;&nbsp;排序:</label>  
			    	<input class="easyui-validatebox" type="text" name="rankchild" style="height:25px;width:100px"></input>
				</div>
				<div style="text-align:right; padding-right: 20px">
					<input type="submit" value="提交" />
				</div>
			</form>
		</div> 
	<div id="dd"></div> 
</body>  
</html>
